$(function () {
    layui.use('layer', function (layer) {
        var login = {
            init: function () {
                $("#imageCode").on("click", function () {
                    login.imageCode(this);
                });
                $("#submit").on("click", function () {
                    var userName = $("#userName").val();
                    $.smart.isNotBlankMsg(userName, "账户不能为空", 5);
                    var passWord = $("#passWord").val();
                    $.smart.isNotBlankMsg(passWord, "密码不能为空", 5);
                    var imageCode = $("#imgCode").val();
                    $.smart.isNotBlankMsg(imageCode, "验证码不能为空", 5);
                    $.ajax({
                        type: 'post',
                        url: $.smart.ctx + '/security_login',
                        data: {"userName": userName, "passWord": passWord, "imageCode": imageCode},
                        async: true, //false同步，true 异步
                        dataType: 'json',
                        success: function (data) {
                            if (data.status == "1") {
                               location.href = $.smart.ctx + data.data;
                            } else {
                                $("#imageCode").click();
                                layer.msg(data.msg, {icon: 5});
                            }

                        }
                    });

                });
            },
            imageCode: function (self) {
                $(self).attr("src", $.smart.ctx + "/login/imgCode.do?date=" + Math.random());
            }
        };
        login.init();

    })
});